home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / video / zapem-0.000 / zapem-0 / zapem / Keyboard.cc < prev    next >
C/C++ Source or Header  |  1995-05-06  |  1KB  |  90 lines

  1. /*    Copyright Alex Hornby 1994/1995. All rights reserved.
  2.      See file README for details
  3. */
  4.  
  5. /*    This really needs improving, until it is I recommend joystick 
  6.     control.
  7. */
  8.  
  9. #include <iostream.h>
  10. #include <vga.h>
  11. #include "Keyboard.h"
  12.  
  13. Keyboard::Keyboard() : Control()
  14. {
  15.     //calibrate();
  16.     left='z';right='x';up=';';down='.';fire1=' ';
  17. }
  18.  
  19. int
  20. Keyboard::getkey(void)
  21. {
  22.     int k=-1,j=25;
  23.     while(k==-1)
  24.         k=vga_getkey();
  25.     while(j!=-1)
  26.         j=vga_getkey();
  27.     return k;
  28. }
  29.  
  30. void
  31. Keyboard::calibrate(void)
  32. {
  33.     cout << "Press key for LEFT\n";
  34.     left=getkey();
  35.     cout << "Press key for RIGHT\n";
  36.     right=getkey();
  37.     cout << "Press key for UP\n";
  38.     up=getkey();
  39.     cout << "Press key for DOWN\n";
  40.     down=getkey();
  41.     cout << "Press key for FIRE1\n";
  42.     fire1=getkey();
  43.     cout << "Press key for FIRE2\n";
  44.     fire2=getkey();
  45. }
  46.  
  47. void
  48. Keyboard::fetch(void)
  49. {
  50.     static int scount;
  51.     int key=vga_getkey();
  52.     if(key==0)
  53.     {
  54.         if(scount>1)
  55.         {
  56.             scount=0;
  57.             for(int i=0;i<FIRE4;i++)
  58.                 last[i]=false;
  59.             last[STRAIGHT]=true;
  60.         }
  61.         else
  62.             scount++;
  63.     }
  64.     else
  65.     {
  66.     scount=0;
  67.     for(int i=0;i<FIRE4;i++)
  68.         last[i]=false;
  69.     if(key==right)
  70.         last[RIGHT]=true;
  71.     else if(key==left)
  72.         last[LEFT]=true;
  73.     else if(key==down)
  74.         last[DOWN]=true;
  75.     else if(key==up)
  76.         last[UP]=true;
  77.     else if(key==fire1) 
  78.         last[FIRE1]=true;
  79.     else if(key==fire2) 
  80.         last[FIRE2]=true;
  81.     else if(key==fire3) 
  82.         last[FIRE4]=true;
  83.     else if(key==fire4) 
  84.         last[FIRE4]=true;
  85.     else if(key==27) 
  86.         last[QUIT]=true;
  87.     }
  88. }
  89.  
  90.